$(document).ready(function(){
    $.fn.dataTableExt.sErrMode = 'throw';
	$.getJSON('controller/cont.monitoring.php',{get_all:true},function(data){
        $('#loader').fadeIn(500);
		$('#list_cari tbody').html('');
		var tab = "";
		if(data.msg){
			$.each(data.daftar, function(index, daftar) {
                tab = "<tr>";
                tab += "<td>" + daftar.no_surat + "</td>";
                //tab += "<td>" + daftar.kanwil +"</td>";
                tab += "<td>" + daftar.nip + "</td>";
                tab += "<td>" + daftar.nama + "</td>";
                tab += "<td>" + daftar.id_cuti + "</td>";
                tab += "<td>" + daftar.id_tujuan + "</td>";
                tab += "<td>" + daftar.tgl_mulai + " s.d " + daftar.tgl_selesai + "</td>";
                tab += "<td>"+daftar.level+"</td>";
                tab += "<td align=\"center\"><a data-toggle=\"modal\" href=\"#myModalUpload\" onclick=\"get_dokumen_pegawai(" + daftar.id_det_usulan + ")\" class=\"btn btn-default btn-sm\" ><span class=\"glyphicon glyphicon-cloud-upload\"></span>&nbsp;Dokumen</a></td>";
                tab += "</tr>";
                $('#list_cari tbody').append(tab);
            });
            $('#list_cari').dataTable({
		        "sPaginationType": "bs_full",
                "bInfo": false,
                "bLengthChange": false,
                "iDisplayLength": 5,
		      }); 
		      $('#list_cari').each(function(){
		        var datatable = $(this);
		        // SEARCH - Add the placeholder for Search and Turn this into in-line form control
		        var search_input = datatable.closest('.dataTables_wrapper').find('div[id$=_filter] input');
		        search_input.attr('placeholder', 'Search');
		        search_input.addClass('form-control input-sm');
		        // LENGTH - Inline-Form control
		        var length_sel = datatable.closest('.dataTables_wrapper').find('div[id$=_length] select');
		        length_sel.addClass('form-control input-sm');
		      }); 
		}else{
			tab += "<tr>"
            tab += "<td colspan=\"8\">Data Tidak Ada</td>";
            tab += "</tr>";
            $('#list_cari tbody').append(tab);
		}
        $('#loader').fadeOut(500);
	});

	return false;
});


function get_dokumen_pegawai(id_det_usulan){
    $.getJSON('controller/cont.dokumen.php',{aksi_list_dokumen_peg:true,id_det_usulan:id_det_usulan},function(data){
        $('#list_dokumen tbody').html('');
        var tab='';
        var i=1;
        if(data.msg){
            $.each(data.list_file,function(index,list_file){
                tab+="<tr>";
                tab+="<td>"+i+"</td>";
                tab+="<td>"+list_file.judul+"</td>";
                // tab += "<td align=\"center\"><button type=\"button\"  class=\"btn btn-default btn-sm\" onclick=\"hapusFile("+list_file.id_dokumen+")\" ><span class=\"glyphicon glyphicon-remove-circle\"></span>&nbsp;Hapus</button></td>";
                tab += "<td align=\"center\"><a data-toggle=\"modal\" class=\"btn btn-default btn-sm\" onclick=\"download_file("+list_file.id_dokumen+")\"><span class=\"glyphicon glyphicon-saved\"></span>&nbsp;Lihat</a></td>";
                tab+="</tr>";
                i++;
            });
            $('#list_dokumen tbody').append(tab);
        }else{
            tab="<tr><td colspan=\"3\">Dokumen Belum Ada</td></tr>";
            $('#list_dokumen tbody').append(tab);
        }
    });
}